package com.engc.common.controller;

import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.engc.common.service.BaseService;
import com.engc.common.utils.BaseUtils;

@Controller
@RequestMapping("/sysRole")
public class SysRole {
	private BaseService baseService;

	@RequestMapping("/view")
	public String view() {
		return "system/sysRole/sysRole";
	}

	@RequestMapping("/insert")
	@ResponseBody
	public Map<String, Object> InserRole(HttpServletRequest request) {
		Map<String, Object> record = BaseUtils.getInsertParam(request);
		record.put("id", baseService.getSeqValue("SEQ_SYS_ROLE"));
		try {
			baseService.Insert("sys_role", record);
			return BaseUtils.getSuccessMessage("新增成功");
		} catch (Exception e) {
			e.printStackTrace();
			return BaseUtils.getErrorMessage("新增失败");
		}
	}

	@RequestMapping("/update")
	@ResponseBody
	public Map<String, Object> UpdateRole(HttpServletRequest request) {
		Map<String, Object> record = BaseUtils.getUpdateParam(request, "id");
		try {
			baseService.Update("sys_role", record, "id=?",
					request.getParameter("id"));
			return BaseUtils.getSuccessMessage("修改成功!");
		} catch (Exception e) {
			e.printStackTrace();
			return BaseUtils.getErrorMessage("修改失败!");
		}
	}

	@RequestMapping("/delete")
	@ResponseBody
	public Map<String, Object> DelRole(@RequestParam("id") String id) {
		try {
			baseService.Delete("sys_role", "id=?", id);
			return BaseUtils.getSuccessMessage("删除成功!");
		} catch (Exception e) {
			e.printStackTrace();
			return BaseUtils.getErrorMessage("删除失败!");
		}
	}
	@Resource
	public void setBaseService(BaseService baseService) {
		this.baseService = baseService;
	}

}
